package com.design.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * 享元工厂角色
 */
public class FlyweightFactory {

    private static Map<String, Flyweight> pool = new HashMap<>();


    public static Flyweight getFlyweight(String key) {
        if (!pool.containsKey(key)) {
            System.out.println("具体享元" + key + "已经存在，被成功获取！");
            Flyweight flyweight = new ConcreteFlyweight(key);
            pool.put(key, flyweight);
        }
        return pool.get(key);
    }
}
